import React from 'react';

import {
  BrowserRouter as Router,
  Route,
  NavLink,
  Switch,
  Redirect,
} from 'react-router-dom';
import './base.css';

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <div>
          <h1>app组件</h1>

          <NavLink activeClassName="xxx" to="/home">
            调到Home
          </NavLink>
          <br />
          <NavLink exact to="/my">
            调到我的音乐
          </NavLink>
          <br />
          <NavLink to="/friend">调到朋友</NavLink>
          {/* 💥 一般Route都会包在Switch之内 */}
          <Switch>
            {/* 💥Redirect一般要配合exact使用, 放在Switch中的第一个 */}
            <Redirect from="/" to="/home" exact />
            <Route path="/home" component={Home} />

            <Route path="/my" component={MyMusic} />
            <Route path="/friend" component={Friend} />

            {/* 404: 不写path, 一放在Switch的最后一个 */}
            <Route component={NotFound} />
          </Switch>
        </div>
      </Router>
    );
  }
}

function NotFound(params) {
  return <h1>404页面</h1>;
}

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic() {
  return <h1>我是我的音乐件</h1>;
}

function Friend() {
  return <h1>我是朋友组件</h1>;
}
